package main

import (
	"fmt"
	"math"
	"time"
)

func threeSumClosest(nums []int, target int) int {
	lengths := len(nums)
	result := nums[0] + nums[1] + nums[2]
	for i := 0; i < lengths-2; i++ {
		for j := i + 1; j < lengths-1; j++ {
			for k := j + 1; k < lengths; k++ {
				sum := nums[i] + nums[j] + nums[k]
				fmt.Println("i,j=", i, j, " sum=", sum, " nums[1]= ", nums[i], " nums[2]", nums[j], " nums[3]", nums[k])
				if math.Abs(float64(sum-target)) < math.Abs(float64(result-target)) {
					result = sum
				}
			}
		}
	}

	return result

}

func main() {
	start := time.Now()
	s := []int{-3, -2, -5, 3, -4}
	target := -1

	dec := threeSumClosest(s, target)
	cost := time.Since(start)
	fmt.Println(dec)
	fmt.Println(cost)
}
